/**
 *    Copyright 2009 Seth Albnaese
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.aquiferserver.client.flex
{
	import flash.utils.ByteArray;
	import flexunit.framework.TestCase;
	
	import mx.utils.Base64Decoder;
	import mx.utils.Base64Encoder;
	
	import org.aquiferserver.client.flex.SerializationCodec;
	
	/**
	 * ...
	 * @author bob
	 */
	public class TestSerializationCodec extends TestCase
	{
		
		public function testSerializationCodec() : void
		{
			
			var testObj:Object = { val:0, str:"Hello World", foo:{ test:"Test", num:0 } };
			
			var ba:ByteArray = new ByteArray();
			var enc:Base64Encoder = new Base64Encoder();
			ba.writeObject( testObj );
			ba.position = 0;
			enc.encodeBytes( ba );
			
			var r:String = enc.drain();
			trace( r );
			var dec:Base64Decoder = new Base64Decoder();
			dec.decode( r );
			var f:ByteArray = dec.drain();
			f.position = 0;
			var decObj:Object = f.readObject();
			
			assertEquals("0 = 0", decObj.val, testObj.val );
			assertEquals("Hello World = Hello World", decObj.str, testObj.str);
			assertEquals("Bar = Bar", decObj.foo.num, testObj.foo.num);
			
			
		}
		
	}
	
}